####
#    This syntax details the creation of five model variables used in the paper
#    Gr�mping, Max. 2019. "More Bang for the Buck: Media Freedom and Organizational Strategies in the Agenda-Setting of Human Rights Groups",
#    in: Political Communication, doi: 10.1080/10584609.2018.1551256.
# 
#    Multiple imputation was used to replace missing data in raw survey responses.
#    The imputed data were subsequently used to create five additive indices:
#    ("DEMI.EFFORT.i", "DEMI.FOCUS.i", "DEMI.PROFESS.i", "DEMI.RESOURCES.i", "DEMI.EXPERIENCE.i")
#    
#    The replication of all data analysis used in the final paper is detailed in the separate syntax "Replication syntax-UPCP-2018-0112.R",
#    based on the final dataset "Replication data-UPCP-2018-0112.RData"
#    
#    WARNING: The imputation procedure may require a long running time
####


rm(list=ls())

require(pacman)
pacman::p_load(mi)
pacman::p_load(mice)
pacman::p_load(Amelia)
pacman::p_load(ggplot2)
pacman::p_load(foreach)
pacman::p_load(polycor)
pacman::p_load(psych)


theme_set(theme_bw())
options(scipen=999)


setwd("C:\\ENTER PATH TO WORKING DIRECTORY\\")
load("Indata-Imputation of IVs.RData")


# Figure A.3: Missingness pattern plot of organizational variables before imputation --------

ggsave(plot = Amelia::missmap(miss, col = c("gray88","gray25"), rank.order = T, x.cex = 0.5),
       filename = "Fig A3.jpg", width = 14, height = 7, dpi = 600, units = "in")




# Multiple imputation of missing values -------------------------------

mdf <- mi::missing_data.frame(miss)
show(mdf)
mdf <- change(mdf, y = "A10_budget", what = "type", to = "ordered-categorical")
mdf <- change(mdf, y = "A5_staff", what = "type", to = "ordered-categorical")
mdf <- change(mdf, y = "A7_volunteer", what = "type", to = "ordered-categorical")
mdf <- change(mdf, y = "A8_electcount", what = "type", to = "ordered-categorical")
mdf <- change(mdf, y = "A37_worked", what = "type", to = "ordered-categorical")
mdf <- change(mdf, y = "A38_strategic", what = "type", to = "ordered-categorical")
mdf <- change(mdf, y = "A39_operations", what = "type", to = "ordered-categorical")
mdf <- change(mdf, y = "A40_difficult", what = "type", to = "ordered-categorical")

imputations <- mi(mdf, n.iter=20, n.chains = 20, max.minutes=60, verbose=T)
dfs <- mi::complete(imputations)

imputed <- data.frame(matrix(NA, nrow = 298, ncol = 0))
imputed$A3_card.i <- apply(as.data.frame(foreach(x=1:20,.combine=cbind)%do%{as.numeric(as.character(dfs[[x]][["A3_card"]]))}), 1, median)
imputed$A4_press.i <- apply(as.data.frame(foreach(x=1:20,.combine=cbind)%do%{as.numeric(as.character(dfs[[x]][["A4_press"]]))}), 1, median)
imputed$A4_board.i <- apply(as.data.frame(foreach(x=1:20,.combine=cbind)%do%{as.numeric(as.character(dfs[[x]][["A4_board"]]))}), 1, median)
imputed$A4_admin.i <- apply(as.data.frame(foreach(x=1:20,.combine=cbind)%do%{as.numeric(as.character(dfs[[x]][["A4_admin"]]))}), 1, median)
imputed$A4_finance.i <- apply(as.data.frame(foreach(x=1:20,.combine=cbind)%do%{as.numeric(as.character(dfs[[x]][["A4_finance"]]))}), 1, median)
imputed$A4_committees.i <- apply(as.data.frame(foreach(x=1:20,.combine=cbind)%do%{as.numeric(as.character(dfs[[x]][["A4_committees"]]))}), 1, median)
imputed$A4_socmed.i <- apply(as.data.frame(foreach(x=1:20,.combine=cbind)%do%{as.numeric(as.character(dfs[[x]][["A4_socmed"]]))}), 1, median)
imputed$A4_director.i <- apply(as.data.frame(foreach(x=1:20,.combine=cbind)%do%{as.numeric(as.character(dfs[[x]][["A4_director"]]))}), 1, median)
imputed$A4_hr.i <- apply(as.data.frame(foreach(x=1:20,.combine=cbind)%do%{as.numeric(as.character(dfs[[x]][["A4_hr"]]))}), 1, median)
imputed$A4_rules.i <- apply(as.data.frame(foreach(x=1:20,.combine=cbind)%do%{as.numeric(as.character(dfs[[x]][["A4_rules"]]))}), 1, median)
imputed$A4_legal.i <- apply(as.data.frame(foreach(x=1:20,.combine=cbind)%do%{as.numeric(as.character(dfs[[x]][["A4_legal"]]))}), 1, median)
imputed$A4_1_meet.1.i <- apply(as.data.frame(foreach(x=1:20,.combine=cbind)%do%{as.numeric(as.character(dfs[[x]][["A4_1_meet.1"]]))}), 1, median)
imputed$A4_1_meet.2.i <- apply(as.data.frame(foreach(x=1:20,.combine=cbind)%do%{as.numeric(as.character(dfs[[x]][["A4_1_meet.2"]]))}), 1, median)
imputed$A4_2_recruit.i <- apply(as.data.frame(foreach(x=1:20,.combine=cbind)%do%{as.numeric(as.character(dfs[[x]][["A4_2_recruit"]]))}), 1, median)
imputed$A10_budget.i <- apply(as.data.frame(foreach(x=1:20,.combine=cbind)%do%{as.numeric(as.character(dfs[[x]][["A10_budget"]]))}), 1, median)
imputed$A5_staff.i <- apply(as.data.frame(foreach(x=1:20,.combine=cbind)%do%{as.numeric(as.character(dfs[[x]][["A5_staff"]]))}), 1, median)
imputed$A7_volunteer.i <- apply(as.data.frame(foreach(x=1:20,.combine=cbind)%do%{as.numeric(as.character(dfs[[x]][["A7_volunteer"]]))}), 1, median)
imputed$A8_electcount.i <- apply(as.data.frame(foreach(x=1:20,.combine=cbind)%do%{as.numeric(as.character(dfs[[x]][["A8_electcount"]]))}), 1, median)
imputed$A19_involve_news.i <- apply(as.data.frame(foreach(x=1:20,.combine=cbind)%do%{as.numeric(as.character(dfs[[x]][["A19_involve_news"]]))}), 1, median)
imputed$A19_involve_journalist.i <- apply(as.data.frame(foreach(x=1:20,.combine=cbind)%do%{as.numeric(as.character(dfs[[x]][["A19_involve_journalist"]]))}), 1, median)
imputed$A19_involve_analysis.i <- apply(as.data.frame(foreach(x=1:20,.combine=cbind)%do%{as.numeric(as.character(dfs[[x]][["A19_involve_analysis"]]))}), 1, median)
imputed$A12_issue_participation.i <- apply(as.data.frame(foreach(x=1:20,.combine=cbind)%do%{as.numeric(as.character(dfs[[x]][["A12_issue_participation"]]))}), 1, median)
imputed$A12_issue_humanrights.i <- apply(as.data.frame(foreach(x=1:20,.combine=cbind)%do%{as.numeric(as.character(dfs[[x]][["A12_issue_humanrights"]]))}), 1, median)
imputed$A12_issue_localgov.i <- apply(as.data.frame(foreach(x=1:20,.combine=cbind)%do%{as.numeric(as.character(dfs[[x]][["A12_issue_localgov"]]))}), 1, median)
imputed$A12_issue_parliament.i <- apply(as.data.frame(foreach(x=1:20,.combine=cbind)%do%{as.numeric(as.character(dfs[[x]][["A12_issue_parliament"]]))}), 1, median)
imputed$A12_issue_corrupt.i <- apply(as.data.frame(foreach(x=1:20,.combine=cbind)%do%{as.numeric(as.character(dfs[[x]][["A12_issue_corrupt"]]))}), 1, median)
imputed$A12_issue_education.i <- apply(as.data.frame(foreach(x=1:20,.combine=cbind)%do%{as.numeric(as.character(dfs[[x]][["A12_issue_education"]]))}), 1, median)
imputed$A12_issue_law.i <- apply(as.data.frame(foreach(x=1:20,.combine=cbind)%do%{as.numeric(as.character(dfs[[x]][["A12_issue_law"]]))}), 1, median)
imputed$A12_issue_enviro.i <- apply(as.data.frame(foreach(x=1:20,.combine=cbind)%do%{as.numeric(as.character(dfs[[x]][["A12_issue_enviro"]]))}), 1, median)
imputed$A12_issue_media.i <- apply(as.data.frame(foreach(x=1:20,.combine=cbind)%do%{as.numeric(as.character(dfs[[x]][["A12_issue_media"]]))}), 1, median)
imputed$A12_issue_welfare.i <- apply(as.data.frame(foreach(x=1:20,.combine=cbind)%do%{as.numeric(as.character(dfs[[x]][["A12_issue_welfare"]]))}), 1, median)
imputed$A12_issue_rural.i <- apply(as.data.frame(foreach(x=1:20,.combine=cbind)%do%{as.numeric(as.character(dfs[[x]][["A12_issue_rural"]]))}), 1, median)
imputed$A12_issue_finance.i <- apply(as.data.frame(foreach(x=1:20,.combine=cbind)%do%{as.numeric(as.character(dfs[[x]][["A12_issue_finance"]]))}), 1, median)
imputed$A12_issue_migration.i <- apply(as.data.frame(foreach(x=1:20,.combine=cbind)%do%{as.numeric(as.character(dfs[[x]][["A12_issue_migration"]]))}), 1, median)
imputed$A12_issue_labour.i <- apply(as.data.frame(foreach(x=1:20,.combine=cbind)%do%{as.numeric(as.character(dfs[[x]][["A12_issue_labour"]]))}), 1, median)
imputed$A12_issue_landwater.i <- apply(as.data.frame(foreach(x=1:20,.combine=cbind)%do%{as.numeric(as.character(dfs[[x]][["A12_issue_landwater"]]))}), 1, median)
imputed$A12_issue_foreign.i <- apply(as.data.frame(foreach(x=1:20,.combine=cbind)%do%{as.numeric(as.character(dfs[[x]][["A12_issue_foreign"]]))}), 1, median)
imputed$A13_budget_elections.i <- apply(as.data.frame(foreach(x=1:20,.combine=cbind)%do%{as.numeric(as.character(dfs[[x]][["A13_budget_elections"]]))}), 1, median)
imputed$A13_budget_elections.i <- ifelse(imputed$A13_budget_elections.i > 100, 100, ifelse(imputed$A13_budget_elections.i<0, 0, imputed$A13_budget_elections.i))

plot(imputations)

merge1 <- cbind(miss, imputed)


# Create organizational IVs -------------------------------


### 1) Media effort
merge1$DEMI.EFFORT <- ((merge1$A19_involve_news + merge1$A19_involve_journalist + merge1$A19_involve_analysis)-3)/12
merge1$DEMI.EFFORT.i <- ((merge1$A19_involve_news.i + merge1$A19_involve_journalist.i + merge1$A19_involve_analysis.i)-3)/12

### 2) Specialization
merge1$sum <- (merge1$A12_issue_participation + 
                 merge1$A12_issue_humanrights + 
                 merge1$A12_issue_localgov + 
                 merge1$A12_issue_parliament + 
                 merge1$A12_issue_corrupt + 
                 merge1$A12_issue_education + 
                 merge1$A12_issue_law + 
                 merge1$A12_issue_enviro + 
                 merge1$A12_issue_media + 
                 merge1$A12_issue_welfare + 
                 merge1$A12_issue_rural + 
                 merge1$A12_issue_finance + 
                 merge1$A12_issue_migration + 
                 merge1$A12_issue_labour + 
                 merge1$A12_issue_landwater + 
                 merge1$A12_issue_foreign)
merge1$DEMI.FOCUS <- ((1-(merge1$sum/16))+(merge1$A13_budget_elections/100))/2

merge1$sum.i <- (merge1$A12_issue_participation.i + 
                   merge1$A12_issue_humanrights.i + 
                   merge1$A12_issue_localgov.i + 
                   merge1$A12_issue_parliament.i + 
                   merge1$A12_issue_corrupt.i + 
                   merge1$A12_issue_education.i + 
                   merge1$A12_issue_law.i + 
                   merge1$A12_issue_enviro.i + 
                   merge1$A12_issue_media.i + 
                   merge1$A12_issue_welfare.i + 
                   merge1$A12_issue_rural.i + 
                   merge1$A12_issue_finance.i + 
                   merge1$A12_issue_migration.i + 
                   merge1$A12_issue_labour.i + 
                   merge1$A12_issue_landwater.i + 
                   merge1$A12_issue_foreign.i)
merge1$DEMI.FOCUS.i <- ((1-(merge1$sum.i/16))+(merge1$A13_budget_elections.i/100))/2

merge1$sum <- NULL
merge1$sum.i <- NULL

### 3) Professionalization
merge1$prof1 <- merge1$A3_card
merge1$prof2 <- (merge1$A4_press + merge1$A4_board  + merge1$A4_admin + merge1$A4_finance + merge1$A4_committees + merge1$A4_socmed + merge1$A4_director +merge1$A4_hr + merge1$A4_rules + merge1$A4_legal)/10
merge1$prof3 <- (merge1$A4_1_meet.1-1)/2
merge1$prof4 <- (merge1$A4_1_meet.2-1)/4
merge1$prof5 <- (merge1$A4_2_recruit-1)/2
merge1$DEMI.PROFESS <- (merge1$prof1 + merge1$prof2 + merge1$prof3 + merge1$prof4 + merge1$prof5)/5

merge1$prof1.i <- merge1$A3_card.i
merge1$prof2.i <- (merge1$A4_press.i + merge1$A4_board.i  + merge1$A4_admin.i + merge1$A4_finance.i + merge1$A4_committees.i + merge1$A4_socmed.i + merge1$A4_director.i +merge1$A4_hr.i + merge1$A4_rules.i + merge1$A4_legal.i)/10
merge1$prof3.i <- (merge1$A4_1_meet.1.i-1)/2
merge1$prof4.i <- (merge1$A4_1_meet.2.i-1)/4
merge1$prof5.i <- (merge1$A4_2_recruit.i-1)/2
merge1$DEMI.PROFESS.i <- (merge1$prof1.i + merge1$prof2.i + merge1$prof3.i + merge1$prof4.i + merge1$prof5.i)/5

merge1$prof1 <- NULL
merge1$prof2 <- NULL
merge1$prof3 <- NULL
merge1$prof4 <- NULL
merge1$prof5 <- NULL
merge1$prof1.i <- NULL
merge1$prof2.i <- NULL
merge1$prof3.i <- NULL
merge1$prof4.i <- NULL
merge1$prof5.i <- NULL


### 4)  Resources
merge1$res1 <- (merge1$A10_budget-1)/13
merge1$res2 <- merge1$A5_staff/7
merge1$res3 <- merge1$A7_volunteer/9
merge1$DEMI.RESOURCES <- (merge1$res1 + merge1$res2 + merge1$res3)/3

merge1$res1.i <- (merge1$A10_budget.i-1)/13
merge1$res2.i <- merge1$A5_staff.i/7
merge1$res3.i <- merge1$A7_volunteer.i/9
merge1$DEMI.RESOURCES.i <- (merge1$res1.i + merge1$res2.i + merge1$res3.i)/3

merge1$res1 <- NULL
merge1$res2 <- NULL
merge1$res3 <- NULL
merge1$res1.i <- NULL
merge1$res2.i <- NULL
merge1$res3.i <- NULL


### 5) Longevity
merge1$exp1 <- ifelse((2016 - merge1$A1_founded)/(summary(merge1$A1_founded)[6]-summary(merge1$A1_founded)[1])>1, 1,(2016 - merge1$A1_founded)/(summary(merge1$A1_founded)[6]-summary(merge1$A1_founded)[1]))
merge1$exp2 <- merge1$A8_electcount/5
merge1$DEMI.EXPERIENCE <- (merge1$exp1 + merge1$exp2)/2

merge1$exp1.i <- ifelse((2016 - merge1$A1_founded)/(summary(merge1$A1_founded)[6]-summary(merge1$A1_founded)[1])>1, 1,(2016 - merge1$A1_founded)/(summary(merge1$A1_founded)[6]-summary(merge1$A1_founded)[1]))
merge1$exp2.i <- merge1$A8_electcount.i/5
merge1$DEMI.EXPERIENCE.i <- (merge1$exp1.i + merge1$exp2.i)/2

merge1$exp1 <- NULL
merge1$exp2 <- NULL
merge1$exp1.i <- NULL
merge1$exp2.i <- NULL



# Validate IVs -------------------------------------------------------

## 1) Media effort
test <- (merge1[c("A19_involve_journalist.i",
              "A19_involve_news.i",
              "A19_involve_analysis.i")])

# conduct EFA and extract factors
pc <- polycor::hetcor(test, ML=TRUE) 
faPC <- psych::fa(r=pc$correlations, nfactors=1, n.obs=1176, rotate="varimax")
scores <- psych::factor.scores(data.matrix(test), faPC)
test <- cbind(test, scores$scores)

# correlate factor scores with additive index and test alpha
cor.test(test$MR1, merge1$DEMI.EFFORT.i)  
psych::alpha(test[,1:3])

r1 <- paste("r =", round(cor.test(test$MR1, merge1$DEMI.EFFORT.i)[[4]], digits = 2), ", p < ", ifelse(round(cor.test(test$MR1, merge1$DEMI.EFFORT.i)[[3]], digits = 3)>0.001, round(cor.test(test$MR1, merge1$DEMI.EFFORT.i)[[3]], digits = 3), 0.001))
a1 <- paste("alpha =", paste(round(psych::alpha(test[,1:3])[[1]][,2], digits = 2),collapse=""))


## 2) Specialization
test <- merge1[c("A12_issue_participation.i",
                "A12_issue_humanrights.i",
                "A12_issue_localgov.i",
                "A12_issue_parliament.i",
                "A12_issue_corrupt.i",
                "A12_issue_education.i",
                "A12_issue_law.i",
                "A12_issue_enviro.i",
                "A12_issue_media.i",
                "A12_issue_welfare.i",
                "A12_issue_rural.i",
                "A12_issue_finance.i",
                "A12_issue_migration.i",
                "A12_issue_labour.i",
                "A12_issue_landwater.i",
                "A12_issue_foreign.i",
                "A13_budget_elections.i")]

# conduct EFA and extract factors
pc <- polycor::hetcor(test, ML=TRUE) 
faPC <- psych::fa(r=pc$correlations, nfactors=1, n.obs=298, rotate="varimax")
scores <- psych::factor.scores(data.matrix(test), faPC)
test <- cbind(test, scores$scores)

# correlate factor scores with additive index and test alpha
cor.test(test$MR1, merge1$DEMI.FOCUS.i)  
psych::alpha(test[,1:18])

r2 <- paste("r =", -round(cor.test(test$MR1, merge1$DEMI.FOCUS.i)[[4]], digits = 2), ", p < ", ifelse(-round(cor.test(test$MR1, merge1$DEMI.FOCUS.i)[[3]], digits = 3)>0.001, -round(cor.test(test$MR1, merge1$DEMI.FOCUS.i)[[3]], digits = 3), 0.001))
a2 <- paste("alpha =", paste(round(psych::alpha(test[,1:18])[[1]][,2], digits = 2),collapse=""))


## 3) Professionalization
test <- merge1[c("A3_card.i",
                "A4_board.i",
                "A4_director.i",
                "A4_admin.i",
                "A4_finance.i",
                "A4_press.i",
                "A4_socmed.i",
                "A4_hr.i",
                "A4_legal.i",
                "A4_rules.i",
                "A4_committees.i",
                "A4_1_meet.1.i",
                "A4_1_meet.2.i",
                "A4_2_recruit.i")]

# conduct EFA and extract factors
pc <- polycor::hetcor(test, ML=TRUE) 
faPC <- psych::fa(r=pc$correlations, nfactors=1, n.obs=298, rotate="varimax")
scores <- psych::factor.scores(data.matrix(test), faPC)
test <- cbind(test, scores$scores)

# correlate factor scores with additive index and test alpha
cor.test(test$MR1, merge1$DEMI.PROFESS.i)  
psych::alpha(test[,1:14])

r3 <- paste("r =", round(cor.test(test$MR1, merge1$DEMI.PROFESS.i)[[4]], digits = 2), ", p < ", ifelse(round(cor.test(test$MR1, merge1$DEMI.PROFESS.i)[[3]], digits = 3)>0.001, round(cor.test(test$MR1, merge1$DEMI.PROFESS.i)[[3]], digits = 3), 0.001))
a3 <- paste("alpha =", paste(round(psych::alpha(test[,1:14])[[1]][,2], digits = 2),collapse=""))



## 4) Resources
test <- merge1[c("A10_budget.i",
                 "A5_staff.i",
                 "A7_volunteer.i")]

# conduct EFA and extract factors
pc <- polycor::hetcor(test, ML=TRUE) 
faPC <- psych::fa(r=pc$correlations, nfactors=1, n.obs=298, rotate="varimax")
scores <- psych::factor.scores(data.matrix(test), faPC)
test <- cbind(test, scores$scores)

# correlate factor scores with additive index and test alpha
cor.test(test$MR1, merge1$DEMI.RESOURCES.i)  
psych::alpha(test[,1:3])


## 5) Longevity
merge1$age <- 2016 - merge1$A1_founded
test <- merge1[c("age",
                 "A8_electcount")]

# conduct EFA and extract factors
pc <- polycor::hetcor(test, ML=TRUE) 
faPC <- psych::fa(r=pc$correlations, nfactors=1, n.obs=298, rotate="varimax")
scores <- psych::factor.scores(data.matrix(test), faPC)
test <- cbind(test, scores$scores)

# correlate factor scores with additive index and test alpha
cor.test(test$MR1, merge1$DEMI.EXPERIENCE.i)  
psych::alpha(test[,1:2])




# Figure A.4: Distribution of organizational independent variables --------

g1 <- ggplot(merge, aes(DEMI.EFFORT.i)) +
  geom_histogram(binwidth=0.1) + 
  geom_histogram(aes(x = DEMI.EFFORT), binwidth=0.1, fill = "white", colour = "gray", alpha = 0.2) +
  annotate("text", x = 0.1, y = 95, label = a1, hjust = 0) +
  annotate("text", x = 0.1, y = 85, label = r1, hjust = 0) +
  xlab("Media effort (0-1)") +
  ylab("No. of groups") +
  coord_cartesian(ylim = c(0, 100), xlim = c(0, 1)) +
  theme_minimal()

g2 <- ggplot(merge, aes(DEMI.FOCUS.i)) +
  geom_histogram(binwidth=0.1) + 
  geom_histogram(aes(x = DEMI.FOCUS), binwidth=0.1, fill = "white", colour = "gray", alpha = 0.2) +
  annotate("text", x = 0.1, y = 95, label = a2, hjust = 0) +
  annotate("text", x = 0.1, y = 85, label = r2, hjust = 0) +
  xlab("Specialization (0-1)") +
  ylab("No. of groups") +
  coord_cartesian(ylim = c(0, 100), xlim = c(0, 1)) +
  theme_minimal()

g3 <- ggplot(merge, aes(DEMI.PROFESS.i)) +
  geom_histogram(binwidth=0.1) + 
  geom_histogram(aes(x = DEMI.PROFESS), binwidth=0.1, fill = "white", colour = "gray", alpha = 0.2) +
  annotate("text", x = 0.1, y = 95, label = a3, hjust = 0) +
  annotate("text", x = 0.1, y = 85, label = r3, hjust = 0) +
  xlab("Professionalization (0-1)") +
  ylab("No. of groups") +
  coord_cartesian(ylim = c(0, 100), xlim = c(0, 1)) +
  theme_minimal()

ggsave(plot = multiplot(g1, g2, g3, cols=2), filename = "Fig A4 - new imputation.jpg", width = 6, height = 6, dpi = 600, units = "in")


rm(g1)
rm(g2)
rm(g3)





# Compare new imputation with final dataset -------------------------------

load("Replication data-UPCP-2018-0112.RData")
check <- merge(merge, merge1, by = c("ID"), all.x=F, all.y=T)

plot(jitter(check$DEMI.EFFORT.i.x), jitter(check$DEMI.EFFORT.i.y))
rcorr(check$DEMI.EFFORT.i.x, check$DEMI.EFFORT.i.y)

plot(jitter(check$DEMI.FOCUS.i.x), jitter(check$DEMI.FOCUS.i.y))
rcorr(check$DEMI.FOCUS.i.x, check$DEMI.FOCUS.i.x)

plot(jitter(check$DEMI.PROFESS.i.x), jitter(check$DEMI.PROFESS.i.y))
rcorr(check$DEMI.PROFESS.i.x, check$DEMI.PROFESS.i.x)

plot(jitter(check$DEMI.RESOURCES.i.x), jitter(check$DEMI.RESOURCES.i.y))
rcorr(check$DEMI.RESOURCES.i.x, check$DEMI.RESOURCES.i.x)

plot(jitter(check$DEMI.EXPERIENCE.i.x), jitter(check$DEMI.EXPERIENCE.i.y))
rcorr(check$DEMI.EXPERIENCE.i.x, check$DEMI.EXPERIENCE.i.x)


# Output newly imputed IVs ------------------------------------------------
out <- merge1[c("ID",
                "DEMI.EFFORT.i",
                "DEMI.FOCUS.i",
                "DEMI.PROFESS.i",
                "DEMI.RESOURCES.i",
                "DEMI.EXPERIENCE.i")]

# save(out, file = "Outdata-Imputation of IVs.RData")





